Section 3.5.3.2
Poly, Cubic and Quartic


A quartic surface (quartic cylinder).

Higher order polynomial surfaces may be defined by the use of a poly shape. The syntax is:

poly { ORDER, <T1, T2, T3, .... Tm> }

Where ORDER is a whole number from 2 to 7 inclusively that specifies the order of the equation. T1, T2... Tm are float values for the coefficients of the equation. There are "m" such terms where

m = ((ORDER+1)*(ORDER+2)*(ORDER+3))/6

An alternate way to specify 3rd order polys is:

cubic { <T1, T2,... T20> }

Also 4th order equations may be specified with:

quartic { <T1, T2,... T35> }

Here's a more mathematical description of quartics for those who are interested. Quartic surfaces are 4th order surfaces, and can be used to describe a large class of shapes including the torus, the lemniscate, etc. The general equation for a quartic equation in three variables is (hold onto your hat):

  a00 x^4 + a01 x^3 y + a02 x^3 z+ a03 x^3 + a04 x^2 y^2+
  a05 x^2 y z+ a06 x^2 y + a07 x^2 z^2+a08 x^2 z+a09 x^2+
  a10 x y^3+a11 x y^2 z+ a12 x y^2+a13 x y z^2+a14 x y z+
  a15 x y + a16 x z^3 + a17 x z^2 + a18 x z + a19 x+
  a20 y^4 + a21 y^3 z + a22 y^3+ a23 y^2 z^2 +a24 y^2 z+
  a25 y^2 + a26 y z^3 + a27 y z^2 + a28 y z + a29 y+
  a30 z^4 + a31 z^3 + a32 z^2 + a33 z + a34 = 0

To declare a quartic surface requires that each of the coefficients (a0 -> a34) be placed in order into a single long vector of 35 terms.

As an example let's define a torus the hard way. A Torus can be represented by the equation:

 x^4 + y^4 + z^4 + 2 x^2 y^2 + 2 x^2 z^2 + 2 y^2 z^2 -
 2 (r0^2 + r1^2) x^2 + 2 (r0^2 - r1^2) y^2 -
 2 (r0^2 + r1^2) z^2 + (r0^2 - r1^2)^2 = 0

Where r0 is the "major" radius of the torus, the distance from the hole of the donut to the middle of the ring of the donut, and r1 is the "minor" radius of the torus, the distance from the middle of the ring of the donut to the outer surface. The following object declaration is for a torus having major radius 6.3 minor radius 3.5 (Making the maximum width just under 20).

//Torus having major radius sqrt(40), minor radius sqrt(12) quartic { < 1, 0, 0, 0, 2, 0, 0, 2, 0, -104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 56, 0, 0, 0, 0, 1, 0, -104, 0, 784 > sturm bounded_by { // bounded_by speeds up the render, // see bounded_by // explanation later // in docs for more info. sphere { <0, 0, 0>, 10 } } }

Poly, cubic and quartics are just like quadrics in that you don't have to understand what one is to use one. The file SHAPESQ.INC has plenty of pre-defined quartics for you to play with. The syntax for using a pre-defined quartic is:

object { Quartic_Name }

As with the other shapes, these shapes can be translated, rotated, and scaled. Because they are (almost always) infinite they do not respond to automatic bounding. They can be used freely in CSG because they have a clear defined "inside".

Polys use highly complex computations and will not always render perfectly. If the surface is not smooth, has dropouts, or extra random pixels, try using the optional keyword "sturm" in the definition. This will cause a slower, but more accurate calculation method to be used. Usually, but not always, this will solve the problem. If sturm doesn't work, try rotating, or translating the shape by some small amount. See the sub-directory MATH for examples of polys in scenes.

There are really so many different quartic shapes, we can't even begin to list or describe them all. If you are interested and mathematically inclined, an excellent reference book for curves and surfaces where you'll find more quartic shape formulas is:

  "The CRC Handbook of Mathematical Curves and Surfaces"  David von Seggern
  CRC Press
  1990

Section 3.5.3.3
Quadric


A quadric surface (paraboloid).

Quadric surfaces can produce shapes like ellipsoids, spheres, cones, cylinders, paraboloids (dish shapes), and hyperboloids (saddle or hourglass shapes). NOTE: Do not confuse "quaDRic" with "quaRTic". A quadric is a 2nd order polynomial while a quartic is 4th order. Quadrics render much faster and are less error-prone.

A quadric is defined in POV-Ray by:

quadric { <A,B,C>, <D,E,F>, <G,H,I>, J }

where A through J are float expressions.

This defines a surface of x,y,z points which satisfy the equation:

  A x^2   + B y^2   + C z^2 +
  D xy    + E xz    + F yz +
  G x     + H y     + I z    + J = 0

Different values of A,B,C,...J will give different shapes. So, if you take any three dimensional point and use its x, y, and z coordinates in the above equation, the answer will be 0 if the point is on the surface of the object. The answer will be negative if the point is inside the object and positive if the point is outside the object. Here are some examples:

  X^2 + Y^2 + Z^2 - 1 = 0  Sphere
  X^2 + Y^2 - 1 = 0        Infinite cylinder along the Z axis
  X^2 + Y^2 - Z^2 = 0      Infinite cone along the Z axis

The easiest way to use these shapes is to include the standard file "SHAPES.INC" into your program. It contains several pre-defined quadrics and you can transform these pre-defined shapes (using translate, rotate, and scale) into the ones you want.

You can invoke them by using the syntax,

object { Quadric_Name }

The pre-defined quadrics are centered about the origin <0, 0, 0> and have a radius of 1. Don't confuse radius with width. The radius is half the diameter or width making the standard quadrics 2 units wide.

Some of the pre-defined quadrics are,

  Ellipsoid
  Cylinder_X, Cylinder_Y, Cylinder_Z
  QCone_X, QCone_Y, QCone_Z
  Paraboloid_X, Paraboloid_Y, Paraboloid_Z

For a complete list, see the file SHAPES.INC.


Section 3.5.4
Constructive Solid Geometry

POV-Ray supports Constructive Solid Geometry (CSG) with four different operations: difference, intersection, merge and union.

Section 3.5.4.1
About CSG

Constructive Solid Geometry is a technique for combining two or more objects to create a new object. It only works with solid objects, i.e. objects that have a well-defined interior. This is the case for all objects described in the sections "Finite Solid Primitives" and "Infinite Solid Primitives" .

CSG is based on the three boolean operations and, or and negate.

CSG shapes may be used in CSG shapes. In fact, CSG shapes may be used anyplace that a standard shape is used.

The order of the component shapes with the CSG doesn't matter except in a difference shape. For CSG differences, the first shape is visible and the remaining shapes are cut out of the first.

Constructive solid geometry shapes may be translated, rotated, or scaled in the same way as any shape. The shapes making up the CSG shape may be individually translated, rotated, and scaled as well.

When using CSG, it is often useful to invert a shape so that it's inside-out. The appearance of the shape is not changed, just the way that POV-Ray perceives it. The inverse keyword can be used to do this for any shape.

When inverse is used, the "inside" of the shape is flipped to become the "outside". For planes, "inside" is defined to be "in the opposite direction to the "normal" or "up" direction.

Note that performing an intersection between a shape and some other inverse shapes is the same as performing a difference. In fact, the difference is actually implemented in this way in the code.


Section 3.5.4.2
Inside and Outside

Most shape primitives, like spheres, boxes, and blobs, divide the world into two regions. One region is inside the surface and one is outside.

Given any point in space, you can say it's either inside or outside any particular primitive object (well, it could be exactly on the surface, but numerical inaccuracies will put it to one side or the other).

Even planes have an inside and an outside. By definition, the surface normal of the plane points towards the outside of the plane. (For a simple floor, for example, the space above the floor is "outside" and the space below the floor is "inside". For simple floors this in un-important, but for planes as parts of CSG's it becomes much more important). CSG uses the concepts of inside and outside to combine shapes together. Take the following situation:

Note: The diagrams shown here demonstrate the concepts in 2D and are intended only as an analogy to the 3D case.

Note that the triangles and triangle-based shapes cannot be used as solid objects in CSG since they have no clear inside and outside.

In this diagram, point 1 is inside object A only. Point 2 is inside B only. Point 3 is inside both A and B while point 0 is outside everything.


Section 3.5.4.3
Union


The union of a box and a cylinder.

Unions are simply "glue", used to bind two or more shapes into a single entity that can be manipulated as a single object. The image above shows the union of A and B. The new object created by the union operation can then be scaled, translated, and rotated as a single shape. The entire union can share a single texture, but each object contained in the union may also have its own texture, which will override any matching texture statements in the parent object.

union { box { <-1.5, -1, -1>, <0.5, 1, 1> pigment { Red } } cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 pigment { Green } } }

This union will contain three spheres. The first sphere is explicitly colored Red while the other two will be shiny blue. Note that the shiny finish does NOT apply to the first sphere. This is because the "pigment {Red}" is actually shorthand for "texture {pigment {Red}}". It attaches an entire texture with default normals and finish. The textures or pieces of textures attached to the union apply ONLY to components with no textures. These texturing rules also apply to intersection, difference and merge as well.

Earlier versions of POV-Ray placed restrictions on unions so you often had to combine objects with composite statements. Those earlier restrictions have been lifted so composite is no longer needed. Composite is still supported for backwards compatibility but it is recommended that union now be used in it's place since future support for the composite keyword is not guaranteed.


Section 3.5.4.4
Intersection

A point is inside the intersection if it's inside both A AND B. This "logical AND's" the shapes and gets the common part, most useful for "cutting" infinite shapes off. The diagram below consists of only those parts common to A and B.


The intersection between a box and a cylinder.

For example:

intersection { box { <-1.5, -1, -1>, <0.5, 1, 1> pigment { Red } } cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 pigment { Green } } }

Section 3.5.4.5
Difference

A point is inside the difference if it's inside A but not inside B. The results is a "subtraction" of the 2nd shape from the first shape.


A cylinder is subtracted from a box..

For example:

difference { box { <-1.5, -1, -1>, <0.5, 1, 1> pigment { Red } } cylinder { <0.5, 0, -1>, <0.5, 0, 1>, 1 pigment { Green } } }

Section 3.5.4.6
Merge

As can be seen in the image for union, the inner surfaces where the objects overlap are still present. On transparent or clipped objects these inner surfaces cause problems. A merge object works just like union but it eliminates the inner surfaces like shown in the figure.


Transparent union showing inner surfaces.


Transparent merge without inner surfaces.


Section 3.5.5
Light Sources

The last object we'll cover is the light source. Light sources have no visible shape of their own. They are just points or areas which emit light. Their full syntax is:

light_source { <CENTER> color <COLOUR> [ spotlight ] [ point_at <POINT> ] [ radius RADIUS ] [ falloff FALLOFF ] [ tightness TIGHTNESS ] [ area_light <AXIS1>, <AXIS2>, SIZE1, SIZE2 ] [ adaptive ADAPTIVE ] [ jitter JITTER ] [ looks_like { OBJECT } ] [ fade_distance FADE_DISTANCE ] [ fade_power FADE_POWER ] [ atmospheric_attenuation BOOL ] }

The different type of light sources and the optional modifiers are described in the following sections.


Section 3.5.5.1
Point Lights

A point light source sends light of the specified color uniformly in all directions. Its location is described by the CENTER vector and its color is given by COLOR. It's syntax is:

light_source { <CENTER> color <COLOUR> [ looks_like { OBJECT } ] [ fade_distance FADE_DISTANCE ] [ fade_power FADE_POWER ] [ atmospheric_attenuation BOOL ] }

Section 3.5.5.2
Spotlights

A spotlight is a point light source where the rays of light are constrained by a cone. The light is bright in the center of the spotlight and falls off/darkens to soft shadows at the edges of the circle.

The syntax is:

light_source { <CENTER> color <COLOUR> spotlight point_at <POINT> radius RADIUS falloff FALLOFF tightness TIGHTNESS [ looks_like { OBJECT } ] [ fade_distance FADE_DISTANCE ] [ fade_power FADE_POWER ] [ atmospheric_attenuation BOOL ] }

The spotlight is identified by the "spotlight" keyword. Its located at CENTER and points at POINT. The following illustrations will be helpful in understanding how these values relate to each other:


Spotlight center and point_at.

Spotlights also have three other parameters: radius, falloff, and tightness.

Think of a spotlight as two nested cones. The inner cone is specified by the radius parameter, and is fully lit. The outer cone is the falloff cone beyond which there is no light. The values for these two parameters are half the opening angles of the corresponding cones.

The tightness value specifies how quickly the light dims, or falls off, in the region between the radius (full brightness inside) cone and the falloff (full darkness outside) cone. The default value for tightness is 10. Lower tightness values will make the spot have very soft edges. High values will make the edges sharper, the spot "tighter". Values from 1 to 100 are acceptable.

Spotlights may be used anyplace that a normal light source is used. Like normal light sources, they are invisible points. They are treated as shapes and may be included in CSG shapes. They may also be used in conjunction with area lights.


Next Section
Table Of Contents